//
//  DLInfoBgScrollView.m
//  delongzhitou
//
//  Created by Mr.Wang on 2018/11/26.
//  Copyright © 2018 delongzhitou. All rights reserved.
//

#import "DLInfoBgScrollView.h"
#import "DLInfoBgView.h"

@implementation DLInfoBgScrollView

- (instancetype) initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self.loadedIndex = [NSMutableArray array];
    }
    return self;
}

- (void) updateInfoWithCurrentPage:(NSInteger)currentPage andDataSource:(NSArray *)dataSource {
    
//    NSLog(@"DLInfoBgScrollView-文章数量是：%ld", dataSource.count);
    
    if (![self.loadedIndex containsObject:@(currentPage)]) {
        NSLog(@"没加载过这个页面，新创建");
        _infoView = [[DLInfoBgView alloc] initWithFrame:CGRectMake(self.width *currentPage, 0, self.width, self.height)];
        _infoView.tag = currentPage + 1000;//这句很重要的骚年
        _infoView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_infoView];
    } else {
        NSLog(@"加载过这个页面了,不需要新创建");
    }
    
//    NSLog(@"不论是否加载过 都需要刷新数据");
    
    _infoView = [self viewWithTag:1000 + currentPage];//这句很重要的骚年
    
    _infoView.infoViewDataSource = dataSource;
    
    if (![self.loadedIndex containsObject:@(currentPage)]) {
        [self.loadedIndex addObject:@(currentPage)];
    }
}


@end
